﻿

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using SharedResources.Model;

namespace SharedResources.Utilities
{
    public class UnderlyingData
    {
        //This class is the underlying data accessed from operation in the program

        private static ObservableCollection<Tuple<String, SelectableDataset>> _selectableData;
        public static ObservableCollection<Tuple<String, SelectableDataset>> SelectableData
        {
            get
            {
                if (_selectableData == null)
                {
                    _selectableData = new ObservableCollection<Tuple<string, SelectableDataset>>();
                }
                return _selectableData;
            }
            set { _selectableData = value; }
        }

        public static void AddToDataSets(string dataLabel, SelectableDataset dataset)
        {
            for (int i = 0; i < _selectableData.Count; i++)
            {
                if(_selectableData[i].Item1.Equals(dataLabel))
                {
                    throw new Exception("This data label already exists. There can be no duplicate datalabels.");
                }
            }
            _selectableData.Add(new Tuple<string, SelectableDataset>(dataLabel, dataset));
            OnRaiseDatasetAdded(
                new DatasetAddedEventArgs(dataset.WillVisualise, 
                new Point(dataset.Dataset.MaxX, dataset.Dataset.MaxY),
                new Point(dataset.Dataset.MinX, dataset.Dataset.MinY)));
        }


        public static event EventHandler OnDatasetAdded = delegate { };

        private static void OnRaiseDatasetAdded(EventArgs e)
        {
            OnDatasetAdded(null, e as DatasetAddedEventArgs);
        }
    }
}
